<?php
namespace app\api\controller\customer;

use app\api\controller\BaseUser;
use app\common\model\customer\Subscribe as SubscribeModel;
use think\facade\Request;

class Subscribe extends BaseUser
{
    // 查询本人预约回访内容
    public function getSubscribeList()
    {
        $params = Request::instance()->param();
        $where  = [];
        if (isset($params['CustomerId']) && $params['CustomerId'] != '') {
            $where['CustomerId'] = ['=', $params['CustomerId']];
        }
        $where['BussinessId'] = ['=', $this->user_id];
        $data                 = (new SubscribeModel())->getList($where);
        return myok($data);
    }
    // 添加预约内容
    public function addSubscribe()
    {
        $params = Request::instance()->param();
        // 获取用户信息
        $params['u_id'] = $this->user_id;

        $result = $this->validate($params, 'Subscribe');
        if (true !== $result) {
            return myerr($result);
        }
        // 将内容插入
        $res = (new SubscribeModel())->addSubscribe($params);
        if ($res) {
            return myok('添加成功');
        } else {
            return myerr($res);
        }
    }
    // 查询预约内容
    public function getSubscribe()
    {
        $SubscribeId          = Request::instance()->param('SubscribeId');
        $where['SubscribeId'] = $SubscribeId;
        $data                 = (new SubscribeModel())->getList($where);
        return myok($data[0]);
    }
    // 更新预约内容
    public function editSubscribe()
    {
        $params = Request::instance()->param();
        $result = $this->validate($params, 'Subscribe');
        if (true !== $result) {
            return myerr($result);
        }
        // 将内容插入
        $res = (new SubscribeModel())->editSubscribe($params);
        if ($res) {
            return myok('更新成功');
        } else {
            return myerr($res);
        }
    }

    // 修改预约状态
    public function editSubscribeStatus()
    {
        $params = Request::instance()->param();
        $res    = (new SubscribeModel())->editSubscribeStatus($params);
        if ($res) {
            return myok('更新成功');
        } else {
            return myerr($res);
        }
    }

}
